# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('apr' 'apr-devel')
pkgver=1.5.1
pkgrel=1
pkgdesc="The Apache Portable Runtime"
arch=('i686' 'x86_64')
url="http://apr.apache.org/"
makedepends=('libcrypt-devel' 'libuuid-devel')
options=('!libtool')
license=('APACHE')
source=(http://www.apache.org/dist/apr/apr-${pkgver}.tar.bz2
      'apr-1.5.0-msys2.patch'
      'binary-copy.patch'
      'no-undefined.patch'
      'tests-disable_testproc.patch'
      'tests-fix_paths.patch'
      'tests.patch'
      'fix-debian-layout.patch')
md5sums=('5486180ec5a23efb5cae6d4292b300ab'
         'f37eb92108624143993a492969543f71'
         'b2815ff4d642ff19fc659b36cb243eed'
         '1851e752eadbfa1cb6e8c446a19b01e5'
         '678d0d714f063e67b0f537d472e14d11'
         'b6671ff8d5051160e7bf1901d7d6c2e9'
         '15f71301f7ffed1ed30b494afa58727f'
         '7e5d21ea2948914d23f73dd49dc5d04f')

prepare() {
  cd "${srcdir}/apr-${pkgver}"

  patch -p1 -i ${srcdir}/binary-copy.patch
  patch -p1 -i ${srcdir}/no-undefined.patch
  patch -p1 -i ${srcdir}/tests-disable_testproc.patch
  patch -p1 -i ${srcdir}/tests.patch
  patch -p1 -i ${srcdir}/tests-fix_paths.patch
  patch -p1 -i ${srcdir}/apr-1.5.0-msys2.patch
  patch -p1 -i ${srcdir}/fix-debian-layout.patch

  autoreconf -fi
}

build() {
  cd "${srcdir}/apr-${pkgver}"
  ./configure --build=${CHOST} \
      --prefix=/usr \
      --libexecdir=/usr/lib/apr/modules \
      --datadir=/usr/share/apr \
      --enable-layout=Debian \
      ac_cv_header_windows_h=no \
      ac_cv_header_winsock2_h=no

  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}/apr-${pkgver}"
  make -j1 check
}

package_apr() {
  depends=('libcrypt' 'libuuid')
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/{bin,share}
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
  #cp -rf ${srcdir}/dest/usr/share/doc ${pkgdir}/usr/share/
}

package_apr-devel() {
  pkgdesc="Libapr headers and libraries"
  groups=('development')
  depends=("apr=${pkgver}" "libcrypt-devel" "libuuid-devel")
  options=('staticlibs')

  mkdir -p ${pkgdir}/usr/{bin,share}
  cp -f ${srcdir}/dest/usr/bin/*-config ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share/apr ${pkgdir}/usr/share/
}
